package com.huijinhui.wlmtsys.controller;


import com.huijinhui.wlmtsys.enums.AppHttpCodeEnum;
import com.huijinhui.wlmtsys.pojo.dtos.PageDTO;
import com.huijinhui.wlmtsys.pojo.dtos.ResponseResult;
import com.huijinhui.wlmtsys.pojo.entity.*;
import com.huijinhui.wlmtsys.service.EmployService;
import com.huijinhui.wlmtsys.service.TeamsService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@Tag(name = "团队接口")
@RestController
@RequestMapping("/teams")
@RequiredArgsConstructor
@Slf4j
public class TeamsController {

    @Autowired
    private TeamsService teamsService;


    @Operation(summary = "团队查询接口")
    @GetMapping("/list/{depart}")
    public ResponseResult geTeamsList(@PathVariable("depart") Integer depart) {
        log.info("团队查询接口");
        List<WlmtsysTeams> list = teamsService.getTeamsList(depart);
        return ResponseResult.okResult(list);
    }
    @Operation(summary = "admin----团队成员新增接口")
    @PostMapping("/add")
    public  void saveTeam(@RequestBody WlmtsysTeams wlmtsysTeams){
        log.info("admin----团队成员新增接口");
        teamsService.saveTeam(wlmtsysTeams);
    }
    @Operation(summary = "admin----团队成员删除接口")
    @DeleteMapping("/delete/{id}")
    public  void deleteTeam(@PathVariable("id") Integer id){
        log.info("admin----团队成员删除接口");
        teamsService.deleteTeam(id);
    }
    @Operation(summary = "admin----团队成员修改接口")
    @PutMapping("/update")
    public  void updateTeam(@RequestBody WlmtsysTeams wlmtsysTeams){
        log.info("admin----团队成员修改接口");
        teamsService.updateTeam(wlmtsysTeams);
    }

    @Operation(summary = "admin---团队成员分页查询接口")
    @GetMapping("/page")
    public PageDTO<WlmtsysTeams> queryNewsPage(PageQuery query) {
        log.info("团队成员分分页查询接口");
        return teamsService.queryProjectPage(query);
    }

    @Operation(summary = "admin---团队成员ID查询接口")
    @GetMapping("/{id}")
    public ResponseResult getTeamById(@PathVariable("id") Integer id) {
        log.info("admin---团队成员ID查询接口");
        WlmtsysTeams wlmtsysTeams = teamsService.getTeamById(id);
        return ResponseResult.okResult(wlmtsysTeams);
    }

    @PostMapping("/upload")
    public ResponseResult uploadNews(@RequestParam("file") MultipartFile multipartFile, @RequestParam("id") Integer teamsId) {
        log.info("图片接口,{},id:{}", multipartFile, teamsId);
        teamsService.uploadNews(multipartFile, teamsId);
        return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
    }
}

